﻿
@{
    Layout = "";
}
<style>
    .moreHistory {
        margin: 20px 40px 8px 40px;
        background: #f5f5f5;
        color: #fff;
        border-radius: 5px;
        font-size: 18px;
        text-align: center;
        height: 35px;
        line-height: 35px;
    }

        .moreHistory a {
            display: block;
            color: #585858;
            font-size: 16px;
            text-decoration: none;
        }
</style>
<div ng-controller="SearchCtrl">
    <!-- 搜索框 -->
    <div class="flayout_i_searchBox">
        <div class="i_left_searchbox">
            <img src="/Content/images/search.png" alt="搜索icon"><input type="text" maxlength="25" ng-model="Keywords" placeholder="搜索" class="i_search">
        </div>
        <p class="i_searchBtn" ng-click="Search(Keywords)">搜索</p>
    </div>
    <!--end 搜索框 -->
    <!-- 热门搜索 -->
    <div class="i_hot_searchBox">
        <h3 class="i_hot_hd">热门搜索</h3>
        <div class="i_spansBox">
            <span class="i_each_search_span" ng-repeat="keyword in SearchKeywords" ng-click="Search(keyword)">{{keyword}}</span>
        </div>
    </div>
    <!--end 热门搜索 -->
    <!-- 历史搜索 -->
    <div class="i_histroy_searchBox">
        <h3 class="i_histroy_hd">历史搜索</h3>
        <p class="i_del_histroy" ng-click="DelHistory()"><img src="/Content/images/del_histroy.png" alt="删除按钮"></p>
        <div class="i_spansBox">
            <span class="i_each_search_span" ng-repeat="history in reddit.items" ng-click="Search(history.Keywords)">{{history.Keywords}}</span>
        </div>
        <div class="moreHistory" ng-click="reddit.nextPage()" ng-show="!reddit.all"><a href="javascript:void(0)">查看更多历史记录</a></div>
    </div>
    
    <!--end 历史搜索 -->
</div>

<script type="text/javascript">
    App.controller('SearchCtrl', [
            '$scope', '$http', '$rootScope', '$stateParams', '$state', '$filter', 'Reddit',
        function ($scope, $http, $rootScope, $stateParams, $state, $filter, Reddit) {

            //数据初始化
            $http.post("/Product/GetSearchKeywords", {}).then(function (response) {
                $scope.SearchKeywords = response.data;
            });


            $scope.reddit = new Reddit("/Product/SearchHistoryList", { Take: 10 }, function (response) { });
            $scope.reddit.nextPage();

            $scope.DelHistory = function () {
                $http.post("/Product/DelSearchHistory", {}).then(function (response) {
                    $scope.reddit.items = [];
                    $scope.reddit.requestData.skip = 0;
                    $scope.reddit.nextPage();
                });
            }
            var tt = function () {
                $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
            }

            setTimeout(tt, 1000)

            $scope.Search = function (keyword) {
                $http.post("/Product/AddSearchHistory", { keywords: keyword }).then(function (response) {
                    $state.go('shop.productlist', { keywords: keyword, fcId: 0, scId: 0 }, { location: 'replace' });
                });
            }


        }]);
</script>